package com.dtsz.m2.ui.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.android.volley.Request;
import com.dtsz.m2.R;
import com.dtsz.m2.config.UrlConfig;
import com.dtsz.m2.ui.base.BaseActivity;
import com.dtsz.m2.ui.model.EcologyOrder;
import com.dtsz.m2.volley.state.HUCState;

public class OrderDetailsActivity extends BaseActivity {
    private TextView tvPrice, tvContent, tvTime, tvNumber, tvRemake;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_order_details);
        super.onCreate(savedInstanceState);
        tvActionbarTitle.setText("订单详情");
        String orderId = getIntent().getExtras().getString("orderId");
        initData(orderId);

    }

    @Override
    public void initView() {
        super.initView();
        tvPrice = findViewById(R.id.tv_price);
        tvContent = findViewById(R.id.tv_content);
        tvTime = findViewById(R.id.tv_time);
        tvNumber = findViewById(R.id.tv_number);
        tvRemake = findViewById(R.id.tv_remake);
    }

    private void initData(String orderId) {
        pageVo.setId(orderId);
        hucRequestInterfase.executeStr(this, EcologyOrder.class,
                HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.ORDERDETAILS_URL,
                hucParameInterfase.getRequestParameter(pageVo), true);
    }

    @Override
    public void onSuccessfulStrType(int inputType, Object response) {
        super.onSuccessfulStrType(inputType, response);
        switch (inputType) {
            case HUCState.HUC_REQEUST_CODE_1:
                if (response instanceof EcologyOrder) {
                    EcologyOrder ecologyOrder = (EcologyOrder) response;
                    if ("1".equals(ecologyOrder.getBeoState())) {
                        tvPrice.setText("-" + ecologyOrder.getBeoPrice() + "㎡");
                        String beoName = ecologyOrder.getBeoName();
                        if("第一生态".equals(beoName)){
                            tvContent.setText("商品说明：" + ecologyOrder.getBuName() + "向" + ecologyOrder.getBeoName() + "支付");
                        }else{
                            tvContent.setText("商品说明：" + ecologyOrder.getBuName() + "向" + ecologyOrder.getBeoName() + "转币");
                        }
                    } else {
                        tvPrice.setText("+" + ecologyOrder.getBeoPrice() + "㎡");
                        tvContent.setText("商品说明：" + ecologyOrder.getBeoName() + "向" + ecologyOrder.getBuName() + "转币");
                    }

                    tvTime.setText("订单时间：" + ecologyOrder.getCreateTimeStr());
                    tvNumber.setText("订单单号：" + ecologyOrder.getBeoId());
                    tvRemake.setText("备注：" + ecologyOrder.getBeoRemark());
                }
                break;
        }
        loadDismiss();
    }
}
